/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-09-07 11:05:09
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-09-07 11:11:38
 */
import api from "@/api";
import { ListResultDto, PagedListResultDto } from "../types";
import {
  GetDictionaryItemInputDto,
  DictionaryItemDto,
  DictionaryValueDto,
} from "./types";

export default {
  /**
   * 获取单条记录
   * @param id
   * @param data
   * @returns
   */
  get(id: string): Promise<DictionaryItemDto> {
    return api.get("/api/Platform/dictionary/" + id);
  },
  /**
   * 获取列表
   * @param id
   * @param data
   * @returns
   */
  getList(
    data: Partial<GetDictionaryItemInputDto>
  ): Promise<PagedListResultDto<DictionaryItemDto>> {
    return api.get("/api/Platform/dictionary", data);
  },
  /**
   * 获取列表（不分页）
   * @param id
   * @param data
   * @returns
   */
  getAllList(
    data: Partial<GetDictionaryItemInputDto>
  ): Promise<Array<DictionaryItemDto>> {
    return api.get("/api/Platform/dictionary/getall", data);
  },
  /**
   * 获取字典项数据
   * @param name
   * @returns
   */
  getItems(name: string): Promise<Array<DictionaryValueDto>> {
    return api.get(`/api/Platform/dictionary/${name}/items`);
  },
  /**
   * 添加
   * @param id
   * @param data
   * @returns
   */
  create(data: Partial<DictionaryItemDto>): Promise<DictionaryItemDto> {
    return api.post("/api/Platform/dictionary", data);
  },
  /**
   * 修改
   * @param id
   * @param data
   * @returns
   */
  update(
    id: string,
    data: Partial<DictionaryItemDto>
  ): Promise<DictionaryItemDto> {
    return api.put("/api/Platform/dictionary/" + id, data);
  },
  /**
   * 删除
   * @param id
   * @returns
   */
  delete(id: string): Promise<DictionaryItemDto> {
    return api.delete("/api/Platform/dictionary/" + id);
  },
};
